create PROCEDURE [dbo].[bd_proc_deleteRepair]
  @order_id AS varchar(max)
AS
BEGIN
	begin try
		begin tran
			--update 补出勤单
			update bd_repair_attendance
				set is_del = -1
				where order_id = @order_id

			--删除kt_jl中的相关记录
			delete from kt_jl where order_id =  @order_id

			--重新计算考勤
			DECLARE @BeginDate DATE
			 ,@EndDate DATE
			 ,@users VARCHAR(MAX) = ''

			SELECT
				@BeginDate = start_date
			 ,@EndDate = end_date
			FROM bd_repair_attendance
			WHERE order_id = @order_Id


			SELECT
				@users = @users + CAST(u.user_serial AS VARCHAR(100)) + ','
			FROM (
				select distinct user_serial from lr_jl where order_id = @order_id
			) u
			SET @users = SUBSTRING(@users,0, LEN(@users))
			--  INSERT INTO temp_repair
			--  VALUES(@BeginDate, @EndDate, @users, @orderId, GETDATE())

			EXEC bd_proc_timecard_extend @BeginDate, @EndDate, @users, 1

		commit tran
	end try
	begin catch
			DECLARE @errStr VARCHAR(MAX) = ERROR_MESSAGE();
			IF XACT_STATE() <> 0
			BEGIN
			  ROLLBACK TRANSACTION;
			  RAISERROR (@errStr, 16, 1);
			END;
	end catch
END